/*----------------------------页面区域---------------------------------*/
<template>
    <el-card>
        <template #header>
            <div class="card-header">
                <span>server数据库操作代码</span>
				<el-button class="button" type="text" @click="selectText">选中文本</el-button>
                <el-button class="button" type="text" @click="copyCode">一键复制</el-button>
            </div>
        </template>
		<div class="gfcodeboxserver">
    <pre ref="gfcode" class="gfcode">
/* {{ props.data.name }}--------自动化代码---------------------- 开始*/
// 包装对外暴露对象
var {{ props.data.name}} gu{{ props.data.name}}
type gu{{ props.data.name}} struct {}

// Creat--创建记录
func (gu gu{{  props.data.name }}) Creat(ctx context.Context,req *entity.{{ props.data.sqlname }})(err error){
	req.Id = 0
	res1,err1 := dao.{{ props.data.sqlname }}.Ctx(ctx).Data(req).InsertIgnore()
	if err1 != nil {
		return  err1
	}
	res2,err2 := res1.RowsAffected()
	if err2 != nil {
		return err2
	}
	if res2 &lt; 1 {
		err = gerror.New("影响行数小于1")
		return err
	}
	return
}
// Update--更新记录
func (gu gu{{ props.data.name}}) Update(ctx context.Context,req *entity.{{ props.data.sqlname }})(err error){
	res1,err1 := dao.{{ props.data.sqlname }}.Ctx(ctx).Data(req).Where(dao.{{ props.data.sqlname }}.Columns().Id,req.Id).Update()
	if err1 != nil {
		return  err1
	}
	res2,err2 := res1.RowsAffected()
	if err2 != nil {
		return err2
	}
	if res2 == 0 {
		err = gerror.New("影响行数为0")
		return err
	}
	return
}
// React--根据id获取记录
func (gu gu{{ props.data.name}}) React(ctx context.Context,id int)(res *entity.{{ props.data.sqlname }},err error){
	var One *entity.{{ props.data.sqlname }}
	err = dao.{{ props.data.sqlname }}.Ctx(ctx).Where(dao.{{ props.data.sqlname }}.Columns().Id,id).Scan(&amp;One)
	if err != nil {
		return nil, err
	}
	res = One
	return
}
// Delete--根据id删除单条
func (gu gu{{ props.data.name}}) Delete(ctx context.Context,id int)(err error){
	res1,err1 := dao.{{ props.data.sqlname }}.Ctx(ctx).WhereIn(dao.{{ props.data.sqlname }}.Columns().Id,id).Delete()
	if err1 != nil {
		return  err1
	}
	res2,err2 := res1.RowsAffected()
	if err2 != nil {
		return err2
	}
	if res2 == 0 {
		err = gerror.New("影响行数为0")
		return err
	}
	return
}
// DeleteByIds--根据id数组批量删除数据
func (gu gu{{ props.data.name}}) DeleteByIds(ctx context.Context,ids []int)(err error){
	res1,err1 := dao.{{ props.data.sqlname }}.Ctx(ctx).WhereIn(dao.{{ props.data.sqlname }}.Columns().Id,ids).Delete()
	if err1 != nil {
		return  err1
	}
	res2,err2 := res1.RowsAffected()
	if err2 != nil {
		return err2
	}
	if res2 == 0 {
		err = gerror.New("影响行数为0")
		return err
	}
	return
}
// GetList--分页获取记录
func (gu gu{{ props.data.name}}) GetList(ctx context.Context,page *model.Page)(res []*entity.{{ props.data.sqlname }},err error){
	var many []*entity.{{ props.data.sqlname }}
	start := (page.From-1)*10
	limit := page.Limit
	err = dao.{{ props.data.sqlname }}.Ctx(ctx).Where(page.Title).Limit(start,limit).Scan(&amp;many)
	if err != nil {
		return nil, err
	}
	res = many
	return
}

/* {{ props.data.name }}--------自动化代码------------------ 结束*/
    </pre>			
		</div>

    </el-card>
</template>
/*----------------------------逻辑区域---------------------------------*/
<script setup>
import {ref,getCurrentInstance  } from 'vue'
import { useClipboard } from '@vueuse/core'
const { proxy } = getCurrentInstance()
const gfcode = ref(null)
const props = defineProps({
    data: {
        type: Object
    }
})
function copyCode(){
    proxy.$copyText(gfcode.value.innerHTML).then(function (e) {
          proxy.$message.success('复制成功')
          console.log(e)
        }, function (e) {
          proxy.$message.error("复制失败")
          console.log(e)
        })
}
function selectText(){
    var range = document.createRange();
    var referenceNode =  document.getElementsByClassName("gfcodeboxserver").item(0); 
    console.log(referenceNode);
    range.selectNodeContents(referenceNode);
    var selection = window.getSelection();
    selection.removeAllRanges();
    selection.addRange(range) 
}
</script>
<style lang="scss" scoped>
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.text {
    font-size: 14px;
}
.item {
    margin-bottom: 18px;
}
.box-card {
    width: 480px;
}
.gfcode {
    background-color: #f3f4f6;
    padding: 20px;
}
</style>

